@use "../_variables" as *;
@use "sass:color";

.chat-input-wrapper {
  position: relative;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: $chat-width;
  width: 100%;
  margin: 0 auto;

  .chat-input-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-gray-strong);
    padding: 8px 12px 13px;
    border-radius: 8px 8px 0 0;
    font-size: 10px;
    color: var(--text-weak);
    position: absolute;
    width: calc(100% - 20px);
    left: 10px;
    top: 5px;
    transform: translate(0, -100%);
    z-index: 1;

    &.on-limit {
      background: var(--bg-danger-weak);
      color: var(--text-danger);
    }
  }
}

.chat-input {
  padding: 0 8px;
  padding-top: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--stroke-gray-medium);
  border-radius: 12px;
  position: relative;
  z-index: 1;
  background: var(--bg-gray-weak);
  color: var(--text-strong);
  max-width: $chat-width;
  margin: 0 auto;
  width: 100%;

  .drag-overlay {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    background: var(--bg-gray-weak);
    border: 3px dashed var(--stroke-pri-strong);
    border-radius: 12px;
    overflow: hidden;
    z-index: 1;
    display: none;

    &.show {
      display: block;
    }

    .drag-overlay-bg {
      position: absolute;
      width: 100%;
      height: 100%;
      background: var(--bg-pri-weak);
      opacity: 0.5;
    }

    .drag-overlay-text {
      display: flex;
      align-items: center;
      gap: 5px;
      pointer-events: none;
      position: absolute;
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      color: var(--text-pri);
    }
  }

  .abort-btn {
    cursor: pointer;

    &:focus {
      outline: none;
    }
  }

  .input-wrapper {
    width: 100%;
    display: flex;;

    textarea {
      min-height: 96px;
      max-height: 288px;
      width: 100%;
      font-size: 14px;
      padding: 12px;
      border: none;
      border-radius: 8px;
      outline: none;
      resize: none;
      line-height: 20px;
      overflow-y: auto;
      background: var(--bg-gray-weak);
      color: var(--text-strong);

      @include scrollbar;
    }
  }

  .input-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;

    button:not(.custom-button) {
      background: none;
      border: none;
      cursor: pointer;
      height: 44px;
      width: 44px;
      padding: 8px;
      border-radius: 50%;

      &:hover {
        background: var(--bg-gray-op-medium);
      }

      &:disabled {
        opacity: 0.5;
        cursor: not-allowed;
      }

      &:not(.abort-btn) {
        svg {
          fill: var(--text-strong);
        }
      }

      &:focus {
        outline: none;
      }
    }

    .chat-input-tools-container {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: row;
      gap: 4px;
      width: fit-content;

      .tools-btn {
        display: flex;
        align-items: center;
        gap: 8px;
        width: fit-content;
        height: 38px;
        line-height: 1;
        padding: 4px 7px;
        border-radius: 8px;
        font-size: 1em;
        cursor: pointer;
        border: none;
      }
    }
  }

  .file-previews {
    @include scrollbar;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    padding: 12px 0;

    .preview-item {
      position: relative;
      border-radius: 8px;
      display: flex;
      align-items: flex-end;
      height: 70px;
      width: 248px;
      min-width: 240px;

      &.image {
        width: 70px;
        min-width: 70px;

        img {
          width: 64px;
          min-width: 64px;
          height: 64px;
          border-radius: 8px;
          object-fit: cover;
        }
      }

      .file-info {
        display: flex;
        align-items: center;
        gap: 8px;
        padding: 8px;
        border-radius: 8px;
        height: 61px;
        width: 240px;
        text-align: left;
        background: var(--bg-gray-medium);

        .file-icon {
          display: flex;
          align-items: center;
          justify-content: center;

          svg {
            fill: currentColor;
            opacity: 0.7;
          }
        }

        .file-details {
          .file-name {
            font-size: 14px;
            margin-bottom: 2px;
            max-width: 200px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }

          .file-size {
            font-size: 12px;
            opacity: 0.7;
          }
        }
      }

      .remove-preview {
        position: absolute;
        top: 0;
        right: 0;
        width: 22px;
        height: 22px;
        border-radius: 50%;
        background: var(--bg-gray-strong);
        color: var(--text-invert);
        border: none;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        padding: 0;

        &:hover {
          background: var(--bg-gray-medium);
        }

        &:focus {
          outline: none;
        }
      }
    }
  }
}


.chat-input-tools-dropdown {
  font-size: 13px;
  font-weight: 500;

  .search-loading-spinner {
    @include loading-spinner(16px, 3px, var(--text-pri));
  }

  .item:has(.head){
    border-bottom: 1px solid var(--stroke-gray-medium);
  }

  .item:has(.chat-input-tools-option .chat-input-tools-option-right svg.show) {
    background-color: var(--bg-gray-medium);
  }

  .chat-input-tools-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 1;
    gap: 8px;
    font-weight: 500;

    .chat-input-tools-option-left {
      display: flex;
      align-items: center;
      gap: 8px;
    }

    .chat-input-tools-option-right {
      display: flex;
      align-items: center;
      justify-content: center;

      svg {
        opacity: 0;
        color: var(--text-pri);

        &.show {
          opacity: 1;
        }
      }

      .loading-spinner {
        @include loading-spinner(16px, 3px, var(--text-pri));
      }
    }

    .chat-input-tools-option-icon {
      display: flex;
      align-items: center;
      width: 26px;
      height: 26px;
      padding: 4px;
      border-radius: 4px;
      background: var(--bg-gray-medium);
      color: var(--text-weak);
      box-shadow: 0 3px 7px 1px var(--sd);
      flex: 0 0 auto;

      img, svg {
        width: 100%;
        height: 100%;
      }

      &.sub-tool {
        background: transparent;
        box-shadow: none;
      }
    }

    .chat-input-tools-option-label {
      display: flex;
      flex-direction: column;
      align-items: flex-start;
      justify-content: center;

      .chat-input-tools-option-title {
        @include line-clamp(1);
      }

      .chat-input-tools-option-desc {
        font-size: 8px;
        color: var(--text-medium);

        &.error {
          color: var(--text-danger);
        }
      }
    }
  }

  .chat-input-tools-option-toggle-all {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
  }

  .chat-input-tools-description {
    width: 100%;
    font-size: 12px;
    color: var(--text-weak);
    padding: 8px 0;
  }

  .chat-input-tools-error {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;

    .chat-input-tools-error-title {
      width: 100%;
      padding: 8px 0;
      color: var(--text-danger);
      font-size: 16px;
    }

    .chat-input-tools-error-content {
      width: 100%;
      padding: 8px 0;
      color: var(--text-weak);
      font-size: 11px;
    }
  }
}

// Tool mention menu styles
.tool-mention-menu {
  position: fixed;
  background: var(--bg-gray-weak);
  border: 1px solid var(--stroke-gray-medium);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  max-height: 240px;
  overflow-y: auto;
  min-width: 280px;
  max-width: 400px;
  z-index: 1000;
  margin-top: 4px;

  .tool-mention-item {
    padding: 10px 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    border-bottom: 1px solid var(--stroke-gray-weak);
    text-align: left;

    &:last-child {
      border-bottom: none;
    }

    &:hover,
    &.selected {
      background: var(--bg-gray-strong);
    }

    &.no-results {
      cursor: default;
      color: var(--text-weak);
      text-align: center;
      padding: 16px 14px;

      &:hover {
        background: transparent;
      }
    }

    .tool-mention-label {
      font-size: 13px;
      font-weight: 500;
      color: var(--text-strong);
      margin-bottom: 2px;
      text-align: left;
    }

    .tool-mention-description {
      font-size: 11px;
      color: var(--text-medium);
      margin-top: 4px;
      line-height: 1.4;
    }
  }
}